'use strict';

/* Controllers */
app.controller('upPassCtrl', ['$scope', '$http', '$state', 'apiService', '$cookieStore', '$timeout', '$rootScope', 'toaster', function ($scope, $http, $state, apiService, $cookieStore, $timeout, $rootScope, toaster) {
    $rootScope.userObj = $cookieStore.get('cy__member');
    $scope.userInfo = {
        id: $rootScope.userObj['id'],
        username: $rootScope.userObj['username']
    }

    // 更新登录密码
    $scope.updatePass = function () {
        $scope.btn_disabled = true;
        toaster.pop('wait', '提示', '正在提交中...');
        apiService.post({
            modelName: 'member',
            apiName: 'updateMebPwd'
        }, $scope.userInfo, function (data) {
            $scope.btn_disabled = false;
            if (data.code == 200) {
                toaster.clear();
                toaster.pop('success', '提示', data['msc']);
                $scope.userInfo = {
                    id: $rootScope.userObj['id'],
                    username: $rootScope.userObj['username']
                }
            } else {
                toaster.pop('error', '提示', data['msc']);
            }
        }, function (err) {
            $scope.btn_disabled = false;
            toaster.pop('error', '提示', '服务器出小差咯...');
        });
    }
}]);